package com.controller.api;

import com.biz.OpenCityBiz;
import com.controller.backend.BaseController;
import com.core.Result;
import com.core.ResultGenerator;
import com.entity.cond.BaseCond;
import com.entity.model.Hotel;
import com.entity.model.OpenCity;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* Created by jc on 2019/12/07.
*/
@RestController("apiOpenCityController")
@RequestMapping("/api/openCity")
public class OpenCityController extends BaseController<OpenCity>{
    @Autowired
    private OpenCityBiz openCityBiz;


    //开放城市列表
    @RequestMapping(value = "/openCityList")
    public Result openCityList(BaseCond bcond) {
        PageHelper.startPage(bcond.getPageNum(), bcond.getPageSize(), false);
        List<OpenCity> news = openCityBiz.findAll();
        return ResultGenerator.genSuccessResult(news);
    }

    //推荐城市列表
    @RequestMapping(value = "/recommendCityList")
    public Result recommendCityList() {
        List<OpenCity> openCityList = openCityBiz.findRecommendCityList();
        String str = listToString(openCityList);
        return ResultGenerator.genSuccessResult(str);
    }

    public String listToString(List<OpenCity> list) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i).getCityName()).append(",");
        }
        return sb.toString().substring(0, sb.toString().length() - 1);
    }
}
